package org.xyl.context;

import java.util.*;

/**
 * 上下文提取器 - 负责从用户输入中提取关键信息
 */
public class ContextExtractor {
    
    private EntityRecognizer entityRecognizer;
    private IntentClassifier intentClassifier;
    private SessionContextManager sessionContextManager;
    
    public ContextExtractor() {
        this.entityRecognizer = new EntityRecognizer();
        this.intentClassifier = new IntentClassifier();
        this.sessionContextManager = new SessionContextManager();
    }
    
    /**
     * 提取上下文信息
     */
    public ContextExtractionResult extract(String userQuery, String sessionId) {
        // 更新会话上下文
        SessionContext sessionContext = sessionContextManager.getOrCreateSession(sessionId);
        sessionContext.addUserQuery(userQuery);
        
        // 提取实体
        Map<String, List<String>> entities = entityRecognizer.recognizeEntities(userQuery);
        
        // 识别意图
        UserIntent intent = intentClassifier.classifyIntent(userQuery, entities);
        
        return new ContextExtractionResult(userQuery, sessionContext, entities, intent);
    }
}